import { rank_list } from "@/network/api";
import http from "@/network/http";
export default {
  namespaced: true,
  state: {
    topList: [],
    list: [],
    loading:false
  },
  mutations: {
    setList(state, payload) {
      state.topList = payload.topList;
      state.list = payload.list;
    },
    setLoading(state,payload){
      state.loading=payload
    }
  },
  actions: {
    async getRankData(context) {
      context.commit('setLoading',true)
      let {list} = await http.get(rank_list);
      let data=list.map(item=>({
        coverImgUrl:item.coverImgUrl,
        update:item.updateFrequency,
        tracks:item.tracks,
        id:item.id
      }))
      context.commit('setList',{topList:data.splice(0,4),list:data})
      context.commit('setLoading',false)
    },
  },
};
